package com.imageim.yimirror.ui.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.imageim.yimirror.R;
import com.imageim.yimirror.common.ui.GlideUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Yuaihen.
 * on 2018/8/7
 * 廓形报告页面Adapter
 */
public class SilhouetteReportAdapter extends RecyclerView.Adapter<SilhouetteReportAdapter.MySihouetteHolder> {
    private Context mContext;
    private List<String> mData = new ArrayList<>();

    public SilhouetteReportAdapter(Context context, List<String> data) {
        mContext = context;
        mData.addAll(data);
    }

    public void replaceData(List<String> newData) {
        if (mData != null) {
            mData.clear();
            mData.addAll(newData);
        }
        notifyDataSetChanged();
    }

    @NonNull
    @Override
    public MySihouetteHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_silhouette_report, parent, false);
        return new MySihouetteHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull MySihouetteHolder holder, int position) {
        GlideUtils.display(holder.mIvPhoto, mData.get(position));
    }


    @Override
    public int getItemCount() {
        return mData == null ? 0 : mData.size();
    }


    static class MySihouetteHolder extends RecyclerView.ViewHolder {

        private ImageView mIvPhoto;

        public MySihouetteHolder(View itemView) {
            super(itemView);
            mIvPhoto = itemView.findViewById(R.id.iv_photo);
        }
    }
}
